/*
 * 
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','observation_summary');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce){
	$scope.anum=0;
	$scope.bnum=0;
	$scope.cnum=0;
	
	
	//**********主体方法
	
	var queryMainApi=apis.queryAuthCollectObservation;	
	var requestJson={};	
	$scope.queryMain=function(){
		$http({
			method:'post',
			url:queryMainApi,
			data:requestJson,
		}).success(function(response){
			if(response.code=="000000"){
				$scope.queryMainApiCallBack(response);
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("网络出现故障，请确认网络是否连接");
		})
	}
	
	$scope.queryMain();
	
	/*下面为自已编辑部分*/
	
	//调用主接口成功之后的处理方法
	$scope.queryMainApiCallBack=function(response){
		if(response.code=="000000"){
			$scope.list=response.data[0];//一级指标列表
			angular.forEach($scope.list,function(data,index,array){	
				data.oneLevel=index+"."+data[index];
				var count=(Object.getOwnPropertyNames(data).length-2)/2;//二级指标个数
				data.twolist=new Array();
				for(var i=1;i<=count;i++){
					var twolevel={num:"",level:"",problem:""};
					twolevel.num=index+"-"+i;
					var fp="b"+i;						
					var level=eval("data."+fp+"a");
					switch(level){
						case"0":twolevel.level="A";
						$scope.anum++;
						break;
						case"1":twolevel.level="B";
						$scope.bnum++;
						break;
						case"2":twolevel.level="C";
						$scope.cnum++;
						break;
					}
					
					twolevel.problem=eval("data."+fp+"b");
					data.twolist.push(twolevel);
				}						
			});
			console.log($scope.list);
		}else{
			alert(response.errorMsg);
		}
	}
	
})
